#include "stdafx.h"
#include "DisplayMode.h"
#include "Claxa.h"

bool operator == (const DisplayMode & l, const DisplayMode & r)
{
	if (l.Style != r.Style)
		return false;

	if (l.Style == DisplayMode::ObjectOnly ||
		l.Style == DisplayMode::BackgroundOnly)
		return true;

	if (l.SmoothMask != r.SmoothMask ||
		l.InverseMask != r.InverseMask)
		return false;

	if (l.Style == DisplayMode::MattedObject &&
		l.MatteColor != r.MatteColor)
		return false;

	return true;
}

inline byte_color int2color(int c)
	{ return reinterpret_cast<byte_color&>(c); }

inline int color2int(byte_color c)
	{ return reinterpret_cast<const int&>(c); }

void DisplayMode::WriteSettings()
{
	theApp.WriteProfileInt("Display", "Style", Style);
	theApp.WriteProfileInt("Display", "SmoothMask", SmoothMask ? 1 : 0);
	theApp.WriteProfileInt("Display", "InverseMask", InverseMask ? 1 : 0);
	theApp.WriteProfileInt("Display", "MatteColor",	color2int(MatteColor));
	theApp.WriteProfileInt("Display", "RamPreview", RamPreview ? 1 : 0);
}

void DisplayMode::ReadSettings()
{
	Style = (StyleEnum)theApp.GetProfileInt("Display", "Style", Composition);
	if ((unsigned)Style > Composition)
		Style = Composition;

	SmoothMask = theApp.GetProfileInt("Display", "SmoothMask", 1) != 0;
	InverseMask = theApp.GetProfileInt("Display", "InverseMask", 1) != 0;
	MatteColor = int2color(theApp.GetProfileInt("Display", "MatteColor", color2int(ByteColor(255,0,0,128))));
	RamPreview = theApp.GetProfileInt("Display", "RamPreview", 0) != 0;
}

